
Page({

  data: {
    index:2,
    imgSrc:"",
    animationData: {},
    showShade:false,
    showDailyQuestion:false,
    shareList:[],
    shareListLength:0,
  },
  
  onLoad: function (options) {
    
    
    this.getShareList()


  },
  getShareList () {
    let app = getApp()
    wx.request({
      url: app.globalData.url + '/home/listshare',
      data:{
        openId:app.globalData.userInfo.openid,
      },
      success: result => {
        let shareList = result.data.data
        
        this.setData({
          shareList:shareList,
          shareListLength:shareList.length
        })
      }
    })
  },
  randomNum(minNum,maxNum){ 
    return parseInt(Math.random()*(maxNum-minNum+1)+minNum,10); 
  },
  onReady: function () {
    this.animation = wx.createAnimation({
      duration: 700,
      timingFunction: 'ease',
    })
  },
  onShow: function () {
    let app = getApp()
    let i = this.randomNum(8,9)
    this.setData({imgSrc: app.globalData.url + "/" + i + ".JPG"})
  },
  change(event){
    let index = event.currentTarget.dataset.index
    this.setData({index:index})
  },
  upload: function () {
    wx.showToast({
      title: '暂时不可上传',
      icon: 'none',
      duration: 2000
    })    
  },
  shareLink: function () {
    this.setData({showShade:true})
    let height = wx.getSystemInfoSync().windowHeight;
    this.setData({showDailyQuestion:true})
    this.animation.translateY(-height * 0.85).step()
    this.setData({animation: this.animation.export()})
  },
  hide: function () {
    let height = wx.getSystemInfoSync().windowHeight;
    this.setData({showShade:false})
    this.animation.translateY(height * 0.85).step()
    this.setData({animation: this.animation.export()})
    setTimeout(() => {
      this.setData({showDailyQuestion:false})
    }, 500)
  },
  onHide: function () {

  },
  getInputValue1:function(e){
    this.setData({input1:e.detail.value})
  },
  getInputValue2:function(e){
    this.setData({input2:e.detail.value})
  },
  getInputValue3:function(e){
    this.setData({input3:e.detail.value})
  },
  share: function () {
    let app = getApp()
    let fileName = this.data.input1.replace(/(^\s*)|(\s*$)/g, "")
    let description = this.data.input2.replace(/(^\s*)|(\s*$)/g, "")
    let link = this.data.input3.replace(/(^\s*)|(\s*$)/g, "")
    if(fileName != "" && description != "" && link != ""){
      if(link.indexOf("https") == -1){
        wx.showToast({
          title: '链接可能不正确',
          icon: 'none',
          duration: 2000
        })
      }else{
        console.log(fileName, description, link)
        wx.request({
          url: app.globalData.url + '/home/share',
          data:{
            openId:app.globalData.userInfo.openid,
            fileName:fileName,
            description:description,
            link:link,
          },
          success: result => {
            if(result.data.status == 200){
              wx.showToast({
                title: '提交成功',
                icon: 'success',
                duration: 1000
              })            
            }
            this.hide()
            this.getShareList()
          }
        })
      }
    }
    else{
      wx.showToast({
        title: '请填写完整信息',
        icon: 'none',
        duration: 2000
      })
    }
  },
  
  onUnload: function () {

  },
  onPullDownRefresh: function () {

  },
  onReachBottom: function () {

  },
  onShareAppMessage: function () {

  }
})